package org.kirhgoff.mathbot;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Gene {
	private byte closenessToMeWeight;
	private byte growthRateWeight;
	private byte populationWeight;
	private byte threatWeight;
	private byte closenessToEnemyWeight;

	private byte defendNeutralWeight;
	private byte defendMineWeight;
	private byte defendEnemyWeight;
	private byte crashEnemyWeight;
	private byte crashMineWeight;
	private byte crashNeutralWeight;
	private byte defendCrashThreshold;
	
	public static Gene fromPropertyFile (InputStream stream) {
		try {
			Properties props = new Properties ();
			props.load(stream);
			Gene gene = new Gene ();
			gene.closenessToMeWeight = Byte.valueOf((String)props.get("closeness.me"));
			gene.closenessToEnemyWeight = Byte.valueOf((String)props.get("closeness.enemy"));
			gene.growthRateWeight = Byte.valueOf((String)props.get("growthRate"));
			gene.populationWeight = Byte.valueOf((String)props.get("population"));
			gene.threatWeight = Byte.valueOf((String)props.get("threat"));
			gene.defendNeutralWeight = Byte.valueOf((String)props.get("defend.neutral"));
			gene.defendMineWeight = Byte.valueOf((String)props.get("defend.mine"));
			gene.defendEnemyWeight = Byte.valueOf((String)props.get("defend.enemy"));
			gene.crashEnemyWeight = Byte.valueOf((String)props.get("crash.enemy"));
			gene.crashMineWeight = Byte.valueOf((String)props.get("crash.mine"));
			gene.crashNeutralWeight = Byte.valueOf((String)props.get("crash.neutral"));
			gene.defendCrashThreshold = Byte.valueOf((String)props.get("strategy.threshold"));
			return gene;
			
		} catch (IOException e) {
			throw new RuntimeException (e);
		}
	}
		
	
	public Gene() {
	}


	private double toDouble(byte percentage) {
		return ((double)percentage)/100;
	}
	

	public double getClosenessToMeWeight() {
		return toDouble (closenessToMeWeight);
	}

	public double getGrowthRateWeight() {
		return toDouble (growthRateWeight);
	}

	public double getPopulationWeight() {
		return toDouble (populationWeight);
	}

	public double getThreatWeight() {
		return toDouble (threatWeight);
	}

	public double getDefendNeutral() {
		return toDouble (defendNeutralWeight);
	}

	public double getDefendMine() {
		return toDouble (defendMineWeight);
	}

	public double getDefendEnemy() {
		return toDouble (defendEnemyWeight);
	}

	public double getCrashEnemy() {
		return toDouble (crashEnemyWeight);
	}

	public double getCrashMine() {
		return toDouble (crashMineWeight);
	}

	public double getCrashNeutral() {
		return toDouble (crashNeutralWeight);
	}

	public double getDefendCrashThreshold() {
		return toDouble (defendCrashThreshold);
	}

	public double getClosenessToEnemyWeight() {
		return toDouble (closenessToEnemyWeight);
	}

}
